﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BattleNet.DataAccess.Extensions
{
    public static class StringExtensions
    {

        public static T As<T>(this string value) where T : class
        {
            return value as T;
        }

        public static T ToEnum<T>(this string value) where T: struct
        {
            if (String.IsNullOrWhiteSpace(value))
                throw new ArgumentNullException("No Value");
            
            Type t = typeof(T);
            if (!t.IsEnum)
                throw new ArgumentException("Type provided must be an Enum.","T");

            return (T)Enum.Parse(t, value, true);
        }
    }
}
